﻿@{
    ViewBag.Title = "登录日志";
}
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try { ace.settings.check('breadcrumbs', 'fixed') } catch (e) { }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="/Admin/Home">首页</a>
            </li>
            <li>
                <a href="/Admin/Log/LoginLog">登录日志</a>
            </li>
            <li class="active">登录日志列表</li>
        </ul><!-- .breadcrumb -->
        <!-- #nav-search -->
    </div>
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->

                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-header">
                            登录日志列表查看
                        </div>
                        <div class="hidden" id="hidden_filter">
                            @* 把需要搜索的条件放到hidden里面，在table格式化完成的时候直接调用$.html()赋值，免去了在js拼接标签的麻烦 *@
                            <label>
                                @Html.TextBox("username", "", new { @class = "form-control input-small", maxlength="25", style = "width:150px", placeholder = "请输入用户名" })
                            </label>
                            <label>
                                <a href="javascript:Search();" class="btn btn-xs btn-primary">
                                    搜索
                                </a>
                                <i class="fa fa-search"></i>
                            </label>
                        </div>
                        <div class="table-responsive dataTables_wrapper">
                            <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>管理员Id</th>
                                        <th>用户名</th>
                                        <th class="hidden-480">登录地址</th>
                                        <th>登录IP</th>
                                        <th>登录浏览器信息</th>
                                        <th>登录时间</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
</div><!-- /.main-content -->
@section script{
    <script src="/Content/assets/js/jquery.dataTables.min.js"></script>
    <script src="/Content/assets/js/jquery.dataTables.bootstrap.js"></script>
    @*<script type="text/javascript">
        jQuery(function ($) {
            var oTable1 = $('#sample-table-2').dataTable({
                "aoColumns": [
                  { "bSortable": false },
                  null, null, null, null, null,
                  { "bSortable": false }
                ],
                "oLanguage": {
                    "sSearch": "搜索",
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ 共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='/Content/assets/css/images/loading.gif' />"
                },
                "aLengthMenu": [1, 2, 3, 10, 20, 50, 100, "ALL"],
                "iDisplayLength":4,
                "bPaginate": true, //翻页功能
                "bLengthChange": true, //改变每页显示数据数量
                "bFilter": true, //过滤功能
                "bSort": true, //排序功能
                "bInfo": true,//页脚信息
                "bAutoWidth": true//自动宽度
            });


            $('table th input:checkbox').on('click', function () {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

            });


            $('[data-rel="tooltip"]').tooltip({ placement: tooltip_placement });
            function tooltip_placement(context, source) {
                var $source = $(source);
                var $parent = $source.closest('table')
                var off1 = $parent.offset();
                var w1 = $parent.width();

                var off2 = $source.offset();
                var w2 = $source.width();

                if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
                return 'left';
            }
        })
        </script>*@
    <script type="text/javascript">
        $(function () {
            var objTable = $("#sample-table-2").dataTable({
                aoColumns: [
                    { "sClass": "center", "mDataProp": "AdminId","bSortable":false },
                    { "sClass": "center", "mDataProp": "AdminUserName", "bSortable": false },
                    { "sClass": "center", "mDataProp": "AdminLoginAddress", "bSortable": false },
                    { //自定义列sName
                        "mDataProp": "AdminLoginIP",
                        "sClass": "center",
                        "bSearchable": false,
                        "bSortable": false
                        //"fnRender": function (obj) {
                        //    return "11111111111111111";
                        //}
                    },
                    { "sClass": "center", "mDataProp": "AdminLoginBrowser", "bSortable": false },
                    {
                        "sClass": "center",
                        "mDataProp": "AdminLoginTime",
                        "bSortable": false ,
                        "fnRender": function (e) {
                            if (e.aData.AdminLoginTime)
                            {
                                return new Date(Number(e.aData.AdminLoginTime.replace(/\D/g, ''))).toLocaleDateString();
                            }
                        }
                    }
                ],
                "bServerSide": true,//分页，取数据等等的都放到服务端去
                "bProcessing": true,//载入数据的时候是否显示“载入中”
                "aLengthMenu": [10,15, 20, 50, 100],
                "iDisplayStart": 0,
                "iDisplayLength": 10,//首次加载的数据条数
                "bStorable": false,//排序操作在服务端进行，所以可以关了。
                "sAjaxSource": "/Admin/Log/LoginLog",
                "fnServerParams": function (aoData) {

                },
                /*如果加上下面这段内容，则使用post方式传递数据*/
                "fnServerData": function (sSource, aoData, fnCallback) {
                    var username = $("#username").val();
                    aoData.push({ "name": "UserName", "value": username });
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": function (resp) {
                            fnCallback(resp); //服务器端返回的对象的returnObject部分是要求的格式
                        }
                    });
                },
                "oLanguage": {
                    "sSearch": "搜索",
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ 共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='/Content/assets/images/loading.gif' />"
                }
            });
            $("#sample-table-2_filter").html("<form id='filter_form'>" + $("#hidden_filter").html() + "</form>");
            $("#hidden_filter").html("");
        });
        $(document).on("submit", "#filter_form", function () {
            return false;
        });
        function Search() {
            $("#sample-table-2").dataTable().fnDraw();//点搜索重新绘制table。
        }
        $(document).on("click", ".show-detail-json", function () {//取出当前行的数据
            alert(JSON.stringify($("#table_server").DataTable().row($(this).parents("tr")).data()));
        });
    </script>
}
